<?php

namespace App\Transformers\User;

use App\Models\User;
use App\Transformers\Order\OrderTransformer;
use App\Transformers\PromoterLevelTransFormer;
use App\Transformers\StoreCoupon\StoreCouponUserTransformer;
use League\Fractal\TransformerAbstract;

class UserPromoterTransformer extends TransformerAbstract
{

//    protected $defaultIncludes =[
//        'order',
//        'promoterOrder',
//        'userextract',
//        'promoterLevel'
//    ];


    public function transform(User $user)
    {
        return [
            'id' => $user->id,
            'avatar' => $user->avatar ?? '',
            'real_name' => $user->real_name ?? '',
            'nickname' => $user->nickname ?? '',
            'phone' => $user->phone ?? '',
            'balance' => $user->balance ?? '',
            'brokerage_price' => $user->brokerage_price ?? '',
            'is_promoter' => $user->is_promoter ?? 0,
            'is_extension' => $user->is_extension ?? 0,
            'promoter_id' => $user->promoter_id ?? '',
            'promoter_time' => $user->promoter_time ?? '',
            'order_count' => $user->order_count ?? '',
            'children' => $user->children ?? '',
            'created_at' => $user->created_at ? $user->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $user->updated_at ? $user->updated_at->format("Y-m-d H:i:s") : '',
        ];
    }

    //包含用户相关的订单信息
    public function includepromoterOrder(User $user)
    {
        return $this->collection($user->promoterOrder, new OrderTransformer());
    }
    //包含用户相关的订单信息
    public function includeorder(User $user)
    {
        return $this->collection($user->order, new OrderTransformer());
    }

    //用户所包含的提现记录
    public function includeuserextract(User $user)
    {
        return $this->collection($user->userextract, new UserExtractsTransformer());
    }
    //用户所包含的分销等级
    public function includePromoterLevel(User $user){
        return $this->item($user->PromoterLevel, new PromoterLevelTransFormer());
    }

}
